
package DomainLayer;

import java.util.ArrayList;

/**
 * In this class ArrayLists are created, where Product type objects are stored.
 * @author Zsombi
 */
public class ProductRecords
{
    private ArrayList<Product> products = new ArrayList<Product>();

    /**
     * Constructor of ProductRecords class.
     */
    public ProductRecords()
    {   }

    /**
     * Adds an existing Product object into the ProductRecords ArrayList.
     * @param product
     */
    protected void addProduct(Product product)
    {
        products.add(product);
    }

    /**
     * Creates a new Product object.
     * Adds this object to the ProductRecords ArrayList.
     * @param Id
     * @param Name
     * @param Amount
     * @param Price
     * @param Discount
     * @param Rented
     * @param Description
     */
    protected void addProduct(String Id, String Name, int Amount, double Price, double Discount, String Rented, String Description)
    {
        Product product = new Product(Id, Name, Amount, Price, Discount, Rented, Description);
    }

    /**
     * Searches for a Product object by its Name.
     * If found, delete/remove that object from the ProductRecords ArrayList.
     * @param productId
     */
    protected void deleteProduct(String productId)
    {
        for(int i=0; i<products.size(); i++)
        {
            if(products.get(i).getId().equals(productId))
            {
                products.remove(i);
            }
        }
    }

    /**
     * Search for a Product object by its Name.
     * If found, return its information.
     * @param productId
     * @return
     */
    protected Product getProduct(String productId)
    {
        for(int i=0; i<products.size(); i++)
        {
            if(products.get(i).getId().equals(productId))
            {
                return products.get(i);
            }
        }
        return null;
    }

    /**
     * Prints out all the products contained by the ProductRecords ArrayList.
     */
    public void listProducts()
    {
        for(Product product : products)
        {
            System.out.println(products + " /n");
        }
    }
}
